<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <div id="app">
      <h2>模板引用</h2>
      <!-- 用ref属性，结合this.$refs.xxx的方式获取dom节点 -->
      <!-- 如果想拿dom节点，必须要保证在mounted之后 -->
      <div class="flower" ref="flower">花儿</div>
      <button @click="fn">btn</button>

      <hr />

      <input type="text" ref="ipt" />
    </div>

    <script src="./lib/Vue3.js"></script>
    <script>
      const { createApp } = Vue;

      createApp({
        data() {
          return {};
        },
        methods: {
          fn() {
            console.log(document.querySelector(".flower"));
            console.log(this.$refs.flower);
          },
        },
        mounted() {
          this.$refs.ipt.focus();
        },
      }).mount("#app");
    </script>
  </body>
</html>
